#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <iostream>


using std::cout;
using std::endl;

//子线程执行流的入口
//子线程本质上就是一个函数
void * start_routine(void * arg)
{
    cout << "sub thread is running." << endl;
    sleep(5);
    return (void*)1;
}


int main()
{
    pthread_t pthid;
    int ret = pthread_create(&pthid, NULL, start_routine, NULL);
    if(ret != 0) {
        fprintf(stderr, "pthread_create:%s\n", strerror(ret));
        return EXIT_FAILURE;
    }

    cout << "main thread is running, sub thread id:" << pthid << endl;

    //main线程退出时，意味着整个进程退出了，
    //子线程也无法单独存在
    pthread_join(pthid, NULL);
    return 0;
}

